home *** CD-ROM | disk | FTP | other *** search
/ Best Tools for JAVA / Best Tools for JAVA.iso / JAVA_ALL / JDBC / JDBC_011 / JAVA / SQL / DATATRUN.JAV < prev    next >
Encoding:
Text File  |  1996-11-10  |  4.2 KB  |  126 lines

  1. /*
  2.  * Copyright (c) 1996 Sun Microsystems, Inc. All Rights Reserved.
  3.  *
  4.  * Permission to use, copy, modify, and distribute this software
  5.  * and its documentation for NON-COMMERCIAL purposes and without
  6.  * fee is hereby granted provided that this copyright notice
  7.  * appears in all copies. Please refer to the file "LICENSE"
  8.  * for further important copyright and licensing information.
  9.  *
  10.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  11.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  12.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  13.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  14.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  15.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  16.  * 
  17.  * THIS SOFTWARE IS NOT DESIGNED OR INTENDED FOR USE OR RESALE AS ON-LINE
  18.  * CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING FAIL-SAFE
  19.  * PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, AIRCRAFT
  20.  * NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT LIFE
  21.  * SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE
  22.  * SOFTWARE COULD LEAD DIRECTLY TO DEATH, PERSONAL INJURY, OR SEVERE
  23.  * PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH RISK ACTIVITIES").  SUN
  24.  * SPECIFICALLY DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR
  25.  * HIGH RISK ACTIVITIES.
  26.  */
  27.  
  28. package java.sql;
  29.  
  30. /**
  31.  * <P>When JDBC unexpectedly truncates a data value, it reports a
  32.  * DataTruncation warning (on reads) or throws a DataTruncation exception
  33.  * (on writes).
  34.  *
  35.  * <P>The SQLstate for a DataTruncation is "01004".
  36.  */
  37.  
  38. public class DataTruncation extends SQLWarning {
  39.  
  40.     /**
  41.      * <P>Create a DataTruncation object. The SQLState is initialized
  42.      * to 01004, the reason is set to "Data truncation" and the
  43.      * vendorCode is set to the SQLException default.
  44.      *
  45.      * @param index The index of the parameter or column value
  46.      * @param parameter true if a parameter value was truncated
  47.      * @param read true if a read was truncated
  48.      * @param dataSize the original size of the data
  49.      * @param transferSize the size after truncation 
  50.      */
  51.     public DataTruncation(int index, boolean parameter, 
  52.               boolean read, int dataSize, 
  53.               int transferSize) {
  54.     super("Data truncation", "01004");
  55.     this.index = index;
  56.     this.parameter = parameter;
  57.     this.read = read;
  58.     this.dataSize = dataSize;
  59.     this.transferSize = transferSize;
  60.     DriverManager.println("    DataTruncation: index(" + index + 
  61.                   ") parameter(" + parameter +
  62.                   ") read(" + read +
  63.                   ") data size(" + dataSize +
  64.                   ") transfer size(" + transferSize + ")");
  65.     }
  66.  
  67.     /**
  68.      * Get the index of the column or parameter that was truncated.
  69.      *
  70.      * <P>This may be -1 if the column or parameter index is unknown, in 
  71.      * which case the "parameter" and "read" fields should be ignored.
  72.      *
  73.      * @return the index of the truncated paramter or column value.
  74.      */
  75.     public int getIndex() {
  76.     return index;
  77.     }
  78.  
  79.     /**
  80.      * Is this a truncated parameter value?
  81.      *
  82.      * @return True if the value was a parameter; false if it was a column value.
  83.      */
  84.     public boolean getParameter() {
  85.     return parameter;
  86.     }
  87.  
  88.     /**
  89.      * Was this a read truncation?
  90.      *
  91.      * @return True if the value was truncated when read from the database; false
  92.      * if the data was truncated on a write.
  93.      */
  94.     public boolean getRead() {
  95.     return read;
  96.     }
  97.  
  98.     /**
  99.      * Get the number of bytes of data that should have been transferred.
  100.      * This number may be approximate if data conversions were being
  101.      * performed.  The value may be "-1" if the size is unknown.
  102.      *
  103.      * @return the number of bytes of data that should have been transferred
  104.      */
  105.     public int getDataSize() {
  106.     return dataSize;
  107.     }
  108.  
  109.     /**
  110.      * Get the number of bytes of data actually transferred.
  111.      * The value may be "-1" if the size is unknown.
  112.      *
  113.      * @return the number of bytes of data actually transferred
  114.      */
  115.     public int getTransferSize() {
  116.     return transferSize;
  117.     }
  118.  
  119.     private int index;
  120.     private boolean parameter;
  121.     private boolean read;    
  122.     private int dataSize;
  123.     private int transferSize;
  124.  
  125. }
  126.